import requests
import re

url = "https://www.zdaye.com/free/1/"
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36"
}
ip_url = "https://dps.kdlapi.com/api/getdps/?secret_id=o0tfppvezo885whdkya4&signature=eyv5hmqqb32zzg106y24rvrbjkndabfy&num=1&pt=1&format=text&sep=1"
backup_ip = "85.234.83.96"

res = requests.get(ip_url)
if res.status_code == 200:
    japan_ip = res.text.strip()
    response = requests.get(url, headers=headers, proxies={
        "http": f"http://{japan_ip}",
        "https": f"http://{japan_ip}"
    }, timeout=5)
    response.raise_for_status()  # 检查响应状态码
    ips = re.findall(r'<td>([0-9.]+)</td>', response.text, re.S)
    for i in range(0, len(ips), 2):
        if i + 1 < len(ips):
            print(f'http://{ips[i]}:{ips[i + 1]}')
else:
    print(f"获取代理 IP 失败，状态码: {res.status_code}")
    response = requests.get(url, headers=headers, proxies={
        "http": f"http://{backup_ip}",
        "https": f"http://{backup_ip}"
    }, timeout=5)
    response.raise_for_status()
    ips = re.findall(r'<td>([0-9.]+)</td>', response.text, re.S)
    for i in range(0, len(ips), 2):
        if i + 1 < len(ips):
            print(f'http://{ips[i]}:{ips[i + 1]}')
